package com.wc.blue_bridge_history.Java14B.G_最大开支;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/11 14:53
 * @description https://www.lanqiao.cn/problems/3541/learning/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 10010;
    // 按照这次与上次的差值进行排序
    static PriorityQueue<T> q = new PriorityQueue<>(T::compareTo);
    static int n, m;
    static long k, b;

    public static void main(String[] args) {
        m = sc.nextInt();
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            k = sc.nextInt();
            b = sc.nextInt();
            q.add(new T(k, b, 1));
        }
        long res = 0;
        while (m > 0 && !q.isEmpty()) {
            T t = q.poll();
            k = t.k;
            b = t.b;
            n = t.n;

            if (t.p > 0) {
                res += t.p;
                t.n += 1;
                t.p = (k * (n + 1) + b) * (n + 1) - (k * n + b) * n;
                q.add(t);
            }
            m--;
        }
        out.println(res);
        out.flush();
    }

    static class T implements Comparable<T> {
        long k;
        long b;
        // 人数
        int n;
        // 价格
        long p;

        T(long k, long b, int n) {
            this.k = k;
            this.b = b;
            this.n = n;
            p = Math.max(0, k * n + b);
        }


        @Override
        public int compareTo(T o) {
            if (o.p > p) {
                return 1;
            }
            return -1;
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

